<?xml version="1.0" encoding="UTF-8" ?>
<%@ page
	contentType="text/html;charset=UTF-8"
	pageEncoding="UTF-8"
	import="fr.utbm.gi.in56.error.ErrorType"
	import="fr.utbm.gi.in56.message.Message"
	import="java.util.List"
	import="java.util.Date"
	import="java.text.DateFormat"
	import="java.text.SimpleDateFormat"
%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
        <link rel="stylesheet" media="screen" type="text/css" title="Style" href="style.css" />
        <title>L'Entre-Pot</title>
    </head>
    <body>
        <div id ="container">
            <jsp:directive.include file="header.jsp"/>
            <jsp:directive.include file="topMenu.jsp"/>
            <div id="core">
            	<h2 align="center">
            	<% 	String box = (String)request.getAttribute("box");
            		if( box == "in" )
            		{
           		%>Boite de réception
           		<%  }
            		else
            		{
           		%>Messages envoyés
           		<%
           			}
           		%>
            	</h2>
            	
            	<%
            		List< Message > msgList = (List< Message >)request.getAttribute( "msgList" );
            		if( msgList != null )
           			{
            			if( msgList.isEmpty() )
            			{
   				%>
					<div id="searchAd">
						<div id="resultEntry">
							<div id="msgEntryTitle">
								La boite de réception est vide
							</div>
						</div>
					</div>
   				<%
            			}
            			else
            			{
           		%>
            		<div id="searchAd">
           		<%
            				for( Message msg : msgList )
            				{
   				%>	
   						<div id="resultEntry">
							<div id=resultEntryTitle>
				<%				
								if( ! msg.isRead() )
								{
				%>
								<img src="ressources/images/new_message.jpg"></src>&nbsp;
				<%
								}
				%>
								Message à propos de l'annonce "
								<a href="#"><%= msg.getAdBuyTitle() + msg.getAdSellTitle()%></a>"
							</div>
								<div id="resultEntryCore">
								<div id="resultEntryLeft">
									<div id="resultEntryInfo">
										<div id="msgEntryInfoTitle">
											Date
										</div>
										<div id="msgEntryInfoValue">
										<%
											DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
											String date = format.format( msg.getDate() );
										%>
											<%= date %>
										</div>
										<div id="resultEntryInfo">
											<div id="msgEntryInfoTitle">
												De
											</div>
											<div id="msgEntryInfoValue">
											<%= msg.getSender() %>
											</div>
										</div>
									</div>
								</div>
								<div id="msgEntryCenter">
									<div style="display:inline;font-family:default_font_bold;">
										Objet du message :
									</div>
									<%= msg.getSubject() %>
									</br></br>
									<%= msg.getMessage() %>
									</div>
								</div>
							<% 	if( box == "in")
								{
							%>
							<div id="resultEntryFooter">
								<%
									int adBuyId = msg.getAdBuyId();
									int adId = ( adBuyId == 0 ) ? msg.getAdSellId() : adBuyId;
									String adType = ( adBuyId == 0 ) ? "sell" : "buy";
								%>
								<a href="SendMessageServlet?recipient=<%= msg.getSender() %>&adId=<%= adId %>&adType=sell&msgType=answer">
									Répondre
								</a>
							</div>
							<%
								}
							%>
						</div>
					<%} %>
					</div>
				</div>
				<%
            		}
   				}
           		%>
            	
			
			<jsp:directive.include file="footer.jsp"/>
        </div>
    </body>
</html>